package View;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;

import Controller.ControladorPrincipal;
import java.awt.Rectangle;
import java.awt.Font;
import java.awt.Point;
import javax.swing.JProgressBar;
import java.awt.Color;
import java.awt.Label;

public class Splash extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JProgressBar jProgressBar = null;
	private Label lblTitulo = null;

	/**
	 * This is the default constructor
	 */
	public Splash() {
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(300, 200);
		this.setLocation(new Point(300, 300));
		this.setContentPane(getJContentPane());
		this.setLocationRelativeTo(null);
		this.setTitle("JFrame");
		this.setUndecorated(true);
		this.setVisible(true);
		sleep(5000);
	}
	private void sleep(int tempo) {
		try{
			int i;
			for(i=0;i<=100;i++){
				jProgressBar.setValue(i);
				Thread.sleep(tempo/101);
			}
			
			this.dispose();
			new ControladorPrincipal();
		}
		catch(InterruptedException erro){
			JOptionPane.showMessageDialog(null, "Ocorreu um erro inesperado.");
		}
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			lblTitulo = new Label();
			lblTitulo.setBounds(new Rectangle(51, 32, 184, 77));
			lblTitulo.setFont(new Font("Dialog", Font.BOLD, 48));
			lblTitulo.setText("Projeto");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.setBackground(new Color(171, 178, 255));
			jContentPane.add(getJProgressBar(), null);
			jContentPane.add(lblTitulo, null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jProgressBar	
	 * 	
	 * @return javax.swing.JProgressBar	
	 */
	private JProgressBar getJProgressBar() {
		if (jProgressBar == null) {
			jProgressBar = new JProgressBar();
			jProgressBar.setBounds(new Rectangle(21, 138, 255, 14));
			jProgressBar.setValue(0);
		}
		return jProgressBar;
	}

}
